package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
@Transactional
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper tbClueMapper;
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;

    @Override
    public void add(ClueTrackRecordVo clueTrackRecordVo) {
        TbClue tbClue = new TbClue();//创建对象用于封装线索信息
        BeanUtils.copyProperties(clueTrackRecordVo,tbClue); //调用工具类拷贝
        tbClue.setId(clueTrackRecordVo.getClueId());//设置id
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());//设置状态为跟进中
        tbClue.setUpdateBy(SecurityUtils.getUsername());
        tbClue.setUpdateTime(new Date());
        //调用修改方法
        tbClueMapper.updateTbClue(tbClue);

        TbClueTrackRecord tbClueTrackRecord = new TbClueTrackRecord();//创建对象封装线索跟进记录
        BeanUtils.copyProperties(clueTrackRecordVo,tbClueTrackRecord);//调用工具类拷贝
        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());//设置操作人
        tbClueTrackRecord.setCreateTime(new Date());//设置操作时间
        tbClueTrackRecord.setClueId(clueTrackRecordVo.getClueId());//设置线索id
        //调用添加方法
        tbClueTrackRecordMapper.add(tbClueTrackRecord);

    }

    @Override
    public List<TbClueTrackRecord> select(Long clueId) {

        return tbClueTrackRecordMapper.select(clueId);
    }
}
